﻿using Gameplay.PVE.Data;
using UnityEngine;
using UnityEngine.Rendering;

namespace Gameplay.PVE.Entity
{
    public class MortalUnit : UnitBase
    {
        public bool SpecialNpc;
        private RenderComponent renderComponent;
        private ControlComponent controlComponent;
        private bool born = false;
        public override void Initialize(UnitData data)
        {
            base.Initialize(data);
            AddComponent<BehaviorComponent>();
            AddComponent<SearchComponent>();
            AddComponent<MoveComponent>();
            renderComponent = AddComponent<RenderComponent>();
            controlComponent = AddComponent<ControlComponent>();
            OnInitialize();
        }

        protected override void OnBirth()
        {
            base.OnBirth();
            controlComponent.SetCollider(Vector3.zero, new Vector3(1.02f, 1.67f, 0.42f), true);
            if (renderComponent != null)
            {
                renderComponent.ShowStartTime = TimeManager.logicTime;
                renderComponent.IsNeedShowFlag = true;
                if (renderComponent.clothMobileUEMat)
                {
                    renderComponent.clothMobileUEMat.SetInt("_BlendSrcFactor",(int)BlendMode.SrcAlpha);
                    renderComponent.clothMobileUEMat.SetInt("_BlendDstFactor",(int)BlendMode.OneMinusSrcAlpha);
                }

            }
        }

        public override void Play(string action,float speed = 1)
        {
            renderComponent?.Play(action);
            renderComponent?.SetAnimSpeed(speed);
        }

        public override void BeforeUpdate()
        {
            base.BeforeUpdate();
            renderComponent?.BeforeUpdate();
        }

        public override void LateUpdate()
        {
            base.LateUpdate();
            renderComponent?.LateUpdate();
        }

        public override void ValidateShadow(bool enable)
        {
            renderComponent?.ValidateShadow(enable);
        }
    }
}
